import moment from 'moment';
import _ from 'lodash';

export const filterDateParse = (value, formatStr = 'YYYY-MM-DD HH:mm:ss') => {
  return value ? moment(value, 'X').format(formatStr) : '-';
};

export const sleep = (s) => {
  return new Promise((reslove, reject) => {
    setTimeout(() => {
      reslove();
    }, s * 1000);
  });
}

export const genTabelData = async (page, per_page) => {
  let demoObj = {
    id: 1,
    name: '张超',
    sex: 1,
    age: 29,
    educational: '本科',
    job: '前端开发工程师',
    word_years: 6,
    type: '电话',
    progress: 1,
    follower: '张三',
    leader: '李四',
    created_time: '1620806400',
    updated_time: '1620900000'
  };
  let tmpArr = [];
  for(let i = 0; i < per_page; i ++) {
    let tmpObj = _.cloneDeep(demoObj);
    let mockId = (page - 1) * per_page + i + 1;
    tmpObj.id = mockId;
    tmpObj.name = tmpObj.name + mockId;
    tmpArr.push(tmpObj);
  }
  await sleep(2);
  return tmpArr;
}